﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace VideoChatApp
{
    public class MemoryStreamVideoSink : VideoSink
    {

        public VideoFormat CapturedFormat { get; private set; }
        public MemoryStream CapturedVideo { get; private set; }

        protected override void OnCaptureStarted()
        {
            CapturedVideo = new MemoryStream();
        }
        protected override void OnCaptureStopped()
        {
        }
        protected override void OnFormatChange(VideoFormat videoFormat)
        {
            if (CapturedFormat != null)
            {
                throw new InvalidOperationException("Can't cope with change!");
            }
            CapturedFormat = videoFormat;
        }
        protected override void OnSample(long sampleTime, long frameDuration, byte[] sampleData)
        {
            CapturedVideo.Write(sampleData, 0, sampleData.Length);
        }
    }
}
